<template>
  <div class="container">
    <img src="@/assets/images/white_logo.png" alt="logo" class="top-logo" />
    <div class="login-main">
      <div class="form-title"></div>
      <div class="form-main">
        <div class="logo-box">欢迎登录</div>
        <a-form
          ref="formRef"
          class="form"
          :wrapperCol="{ span: 24 }"
          :model="formState"
          :rules="rules"
        >
          <a-form-item name="user" has-feedback>
            <a-input
              v-model:value="formState.user"
              class="diy-input"
              size="large"
              :style="{ width: '100%' }"
              placeholder="请输入用户名"
            />
          </a-form-item>
          <a-form-item name="password" has-feedback>
            <a-input
              v-model:value="formState.password"
              type="password"
              placeholder="请输入密码"
              :style="{ width: '100%' }"
              size="large"
              @keydown.enter="onSubmit"
            />
          </a-form-item>
        </a-form>
        <div class="control">
          <a-button
            :disabled="!formState.password"
            :style="{ height: '50px' }"
            type="primary"
            block
            size="large"
            @click="onSubmit"
          >
            登录
          </a-button>
        </div>
        <div class="use-tip">
          <div>
            <span class="text">建议使用</span>
            <img src="~@/assets/images/login/chrome.png" alt="" class="icon" />
            <span class="text">Chrome、</span>
            <img src="~@/assets/images/login/firefox.png" alt="" class="icon" />
            <span class="text">火狐、</span>
            <img src="~@/assets/images/login/safari.png" alt="" class="icon" />
            <span class="text">Safari浏览器</span>
          </div>
          <div>
            <span class="text">或</span>
            <img src="~@/assets/images/login/360.png" alt="" class="icon" />
            <span class="text">360、</span>
            <img src="~@/assets/images/login/sougou.png" alt="" class="icon" />
            <span class="text">搜狗、</span>
            <img src="~@/assets/images/login/qq.png" alt="" class="icon" />
            <span class="text">QQ等浏览器</span>
            <img src="~@/assets/images/login/fast.png" alt="" class="icon" />
            <span class="text">极速模式</span>
          </div>
        </div>
        <div v-if="loginLoading" class="login-mask">
          <svg viewBox="25 25 50 50" class="circular">
            <circle cx="50" cy="50" r="20" fill="none" class="path" />
          </svg>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import store from '@/store';
import { storage } from '@/utils/Storage';
import { ref } from 'vue';
import { useRouter } from 'vue-router';
const loginLoading = ref(false);
const formRef = ref<any>(null);
const router = useRouter();
const formState = ref({});
const rules = ref({
  user: [{ required: true, trigger: 'blur', message: '请输入用户名' }],
  password: [{ required: true, trigger: 'blur', message: '请输入密码' }]
});
const onSubmit = () => {
  formRef.value.validate().then(() => {
    loginLoading.value = true;
    setTimeout(() => {
      store
        .dispatch('asyncRoute/generateRoutes')
        .then(() => {
          storage.set('isLogin', true);
          router.push('/welcome');
        })
        .finally(() => {
          loginLoading.value = false;
        });
    }, 1500);
  });
};
</script>

<style scoped lang="scss">
.container {
  width: 100vw;
  height: 100vh;
  background: url('@/assets/images/login/bg.png') 50% no-repeat;
  background-size: cover;
  display: flex;
  align-items: center;
  justify-content: center;
  .top-logo {
    position: fixed;
    left: 40px;
    top: 30px;
    height: 50px;
  }
  .login-main {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-evenly;

    .form-title {
      width: 480px;
      height: 560px;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-direction: column;
      h1 {
        font-size: 32px;
        margin-top: 0;
        margin-bottom: 30px;
        color: #fff;
        font-weight: 400;
        letter-spacing: 3px;
      }
      .logo {
        width: 320px;
        height: 400px;
      }
    }
    .form-main {
      width: 480px;
      background: #fff;
      height: 510px;
      border-radius: 6px;
      position: relative;
      .login-mask {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: hsla(0, 0%, 100%, 0.9);
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 99;
        .circular {
          height: 42px;
          width: 42px;
          animation: loading-rotate 2s linear infinite;
          .path {
            animation: loading-dash 1.5s ease-in-out infinite;
            stroke-dasharray: 90, 150;
            stroke-dashoffset: 0;
            stroke-width: 2;
            stroke: #409eff;
            stroke-linecap: round;
          }
        }
      }
      .logo-box {
        position: relative;
        width: 100%;
        font-weight: 700;
        font-size: 20px;
        color: #4c4c4c;
        letter-spacing: 2px;
        padding: 0 40px;
        margin: 15px 0 20px;
        &::before {
          position: absolute;
          top: 50%;
          left: 24px;
          transform: translateY(-50%);
          content: '';
          width: 4px;
          height: 16px;
          background-color: #3e6bea;
          border-radius: 2px;
          display: block;
        }
      }
      .form {
        padding: 0 40px;
        margin-top: 40px;
        .ant-input {
          height: 50px;
          font-size: 14px;
          background-color: #f6f6f6;
          border-radius: 4px;
          margin-bottom: 5px;
          &:focus {
            background: #fff;
          }
        }
      }
      .control {
        width: 100%;
        padding: 0 40px;
        margin-top: 40px;
      }

      .use-tip {
        position: absolute;
        left: 0;
        bottom: 18px;
        width: 100%;
        text-align: center;
        color: #999;
        font-size: 12px;
        div + div {
          margin-top: 3px;
        }
        .text {
          vertical-align: middle;
        }
        .icon {
          width: 15px;
          display: inline-block;
          vertical-align: middle;
        }
      }
    }
  }
}

@media screen and (max-width: 750px) {
  .form-title {
    display: none !important;
  }
  .form-main {
    width: 90vw !important;
    height: 420px !important;
  }
}
</style>
